﻿<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8" />
	<title>登录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<!-- <link rel="stylesheet"  href="/jquery.mobile-1.2.1/jquery.mobile-1.2.1.min.css" /> -->
	<!-- <link rel="stylesheet" href="ios_inspired/styles.css" /> -->
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.7.1/jquery.min.js">
	// all dialog buttons should close their parent dialog
		$(".ui-dialog button").live("click", function() {
			$("[data-role='dialog']").dialog("close");
		});
		$(document).on("mobileinit", function(){
		  $.mobile.defaultPageTransition = "slide";
		});
	</script>
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery-mobile/1.4.5/jquery.mobile.min.js"></script>
	<script src="./md5andbase64.js"></script>
	<script src="./joygo_pub.js"></script>
	<script src="./joygo_des.js"></script>
	<script>
	$(document).ready(function() {
	$("#btnSubmit").click(function() {
		tologin();
	});
	});
    function tologin()
	{
		if (check())
		{
			// showLoader();
			handle_login();
		}
	}

	function handlereturn(data)
	{
		if(data.retcode==0)
		{
			//alert(document.cookie);
			setcookie("loginuserid", data.UserID);
			setcookie("loginusernick", data.UserNick);
			setcookie("loginuserscore", data.UserScore);
			setcookie("sessionkey", data.sessionkey);
			//alert(document.cookie);
			var checkurl=getUrlParam("check");
			if(checkurl=="")
			{
				var url="/joygo/joygo_index.html?userid="+data.UserID;
				url+="&sessionkey=";
				url+=data.sessionkey;
				window.open(url,'_self');
			}
			else
			{
				var url=checkurl;
				var pos=checkurl.indexOf("?");
				if(pos>0)
				{
					url+="&userid="+data.UserID;
				}
				else
				{
					url+="?userid="+data.UserID;
				}
				url+="&sessionkey=";
				url+=data.sessionkey;
				window.open(url,'_self');
			}
		}
		else if(data.retcode==-100)
		{
			setcookie("loginuserid",0);
			alert("邮箱不存在");
		}
		else if(data.retcode==-200)
		{
			setcookie("loginuserid",0);
			alert("密码错误");
		}
		else
		{
			alert("登录错误"+data.retcode);
			setcookie("loginuserid",0);
		}
	}

    function check()
	{
		if ($("#mail").val() == "")
		{
			alert("邮箱不能为空！");
			$("#mail").focus();
			return false;
		}
		if ($("#password").val() == "")
		{
			alert("密码不能为空！");
			$("#password").focus();
			return false;
		}
		return true;
	}
	function getLoginAuthStr(hashpassword)
	{
		var myDate = new Date();
		var time=Math.floor(myDate.getTime()/1000);
		var key1=hashpassword;
		var key2=hashpassword.substr(0,2);
		var key3=hashpassword.substr(2,4);
		var timestr=time.toString();
		var enchex = strEnc(timestr,key1,key2,key3);
		return enchex;
	}
	function handle_login()
	{
		$.ajax({
			type: "POST",
			url: "http://192.168.1.101:8081/cgi-bin/login",
			data: {mail: $("#mail").val(), authstr: getLoginAuthStr(joygo_b64_md5($("#password").val()))},
			beforeSend: function() { },
			success: function(data) {
			hideLoader();
			handlereturn(data);

			},
			failed: function(data) {
			hideLoader();
			alert("network failed");
			}
		});
	}


	</script>

	<style>
		#footerTabs {
			background: #FFF -webkit-radial-gradient(circle, #FFF, #dee2e4);
		}
	</style>


</head>
<body>

<div data-role="page" >
	<table bgcolor="#D7DDDE" width="300">
	<tr><td>
	<div data-role="fieldcontain">
	<label>请输入的注册邮箱并登录:</label>
			<br /><br />
			<label>邮箱:</label>
			<input type="text" id="mail"/>
			<br /><br />
 			<label>密码:</label>
			<input type="password" id="password"/>
			<br />
		</div>
   <div style=" text-align:center;"><input type="button" width="100" id="btnSubmit" value="登录"/> </div>
	</td></td></table>
</div>
</body>
</html>

